package servlet;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class VisitImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public VisitImageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// get the store path of the image on server
		String path=this.getServletContext().getRealPath("/WEB-INF/1.jpg");
		// set buffer
		byte[] buf=new byte[512];
		InputStream in=new FileInputStream(path);
		OutputStream out=response.getOutputStream();
		// set the content-type in the response
		response.setHeader("Content-Type", "image/jpeg");
		int len=0;
		while((len=in.read(buf))!=-1){
			out.write(buf, 0, len);
		}
		
		in.close();
		out.close();
	}

}
